<template>
    <view class="discount">
        <view>
            <text class="iconfont icon-zhekou1 icon"></text>
            <view class="title">
                <text>每日折扣</text>
            </view>
        </view>
        <view class="main">
            <view class="main-content">
                <view class="item" @click="handleDetail(item)" v-for="item in goodsList">
                    <view class="item-content">
                        <Avatar :src='item.photo' :size='size' shape="none" class="photo"></Avatar>
                        <view class="item-text">
                            <view class="item-supplier">
                                <view class="item-supplier-content">
                                    <text class="iconfont icon-xiaotaiyang item-icon"></text>
                                    <text>{{item.supplier}}</text>
                                </view>
                                <view class="item-inventory">
                                    <view>
                                        <text>库存：</text>
                                        <text
                                            style="color:var(--color-theme);font-weight: 600">{{item.inventory}}</text>
                                    </view>
                                </view>
                            </view>
                            <view class="item-title">{{item.name}}</view>
                            <view class="flex">
                                <view class="item-specs">
                                     <FrogTag size='mini'>{{item.specs}}</FrogTag>
                                </view>
                                <view class="item-sales">
                                    <FrogTag size='mini' v-if="item.sales < 100">已售{{item.sales}}</FrogTag>
                                      <FrogTag size='mini' v-if="item.sales > 100">已售{{item.sales}}+</FrogTag>
                                </view>
                            </view>
                            <view class="item-number-wrapper">
                                <view class="flex flex-end">
                                    <view class="flex-1">
                                        <text>￥</text>
                                        <text class="item-number">{{item.promotePrice}}</text>
                                        <text class="item-number-old">￥{{item.price}}</text>
                                    </view>
                                    <view class="flex add-shopping-container">
                                        <text class=" add-shopping-btn minus-btn iconfont icon-jian_sekuai"></text>

                                        <text class="add-shopping-number">0</text>

                                        <text class="add-shopping-btn add-btn iconfont icon-jia"></text>
                                    </view>
                                </view>

                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    import {
        getPromoteGoods
    } from '../../api/goods';
    import Avatar from '../public/avatar/index.vue'
    import FrogTag from '../public/tag/index.vue';
    export default {
        components: {
            Avatar,
            FrogTag
        },
        data() {
            return {
                isCircle: true,
                size: 'inherit',
                src: 'https://demos.themeselection.com/materio-vuetify-vuejs-admin-template/demo-1/images/avatars/avatar-1.png',
                queryParams: {
                    page: 1,
                    limit: 10,
                },
                goodsList: []
            }
        },
        mounted() {
            this.getData();
        },
        methods: {
            async getData() {
                const res = await getPromoteGoods(this.queryParams);
                if (res.result === 0) {
                    this.goodsList = res.data.data;
                }
            },
            handleDetail(item) {
                uni.navigateTo({
                    url: `/pages/index/detail/detail?id=${item.id}`,
                })
            }
        }
    }
</script>


<style>
    .discount {
        background-color: #F5F5F6;
        padding: 6px;
    }

    .title {
        display: inline;
        position: relative;
        font-size: 18px;
        font-weight: 600;
    }


    .title text::before {
        content: '';
        height: 4px;
        width: 100%;
        position: absolute;
        bottom: 0;
        background-color: var(--color-theme);
        border-radius: 10px;
    }


    .icon {
        color: var(--color-theme);
        font-size: 20px;
        padding: 0 4px;
    }


    .main {
        padding: 14px 0;
        padding-bottom: 100px;
    }

    .main-content {
        column-count: 1;
        column-gap: 10px;
    }

    @media (min-width: 414px) {
        .main-content {
            column-count: 2;
        }
    }

    @media (min-width: 768px) {
        .main-content {
            column-count: 3;
        }
    }

    @media (min-width: 1024px) {
        .main-content {
            column-count: 4;
        }
    }

    .item-content {
        width: 100%;
    }


    .item {
        display: inline-block;
        /* width: 100%; */
        border-radius: var(--rounded);
        background-color: #fff;
        margin-top: 10px;
    }


    .photo {
        border-top-right-radius: var(--rounded);
        border-top-left-radius: var(--rounded);

    }

    .item-text {
        background-color: #fff;
        padding: 8px 4px;
        padding-top: 0;
        border-bottom-left-radius: var(--rounded);
        border-bottom-right-radius: var(--rounded);
        position: relative;
    }


    .item-supplier {
        position: absolute;
        background-color: #fff;
        top: -10px;
        /* left: 10px; */
        font-size: 13px;
        padding: 2px 1px;
        border-radius: var(--rounded);
        border: 1px solid #eee;
        color: gray;
        display: flex;
        white-space: nowrap;
        box-sizing: border-box;
        padding: 0 6px;
    }

    .item-supplier-content {
        padding-right: 10px;
    }

    .item-inventory {
        border-left: 1px solid #eee;
        padding-left: 10px;
    }


    .item-title {
        font-size: 18px;
        padding-top: 16px;
    }

    .item-number-wrapper {
        padding: 6px 0;
        color: var(--color-theme);
    }

    .item-number {
        font-size: 18px;

    }

    .item-number::first-letter {
        font-size: 220px;
    }

    .item-number-old {
        font-size: 14px;
        text-decoration: line-through;
        padding-left: 6px;
        display: inline-block;
        color: #aaa;
    }

    .item-icon {
        padding: 0 2px;
    }

    .add-shopping-container,
    .add-shopping-container button {
        color: var(--color-theme);
    }

    .add-shopping-btn {
        border: 1px solid var(--color-theme);
        border-radius: 50%;
        padding: 2px;
        margin: 0 4px;
    }

    .add-shopping-number {
        font-weight: 600;
    }
</style>